import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/views/layout/Layout'
const _import = require('./_import')

Vue.use(Router)
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
Router.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

export const constantRouterMap = [
    { path: '/login', component: _import('login/index'), hidden: true },
    { path: '/401', component: _import('errorPage/401'), hidden: true },
    { path: '/404', component: _import('errorPage/404'), hidden: true },
    { path: '/', component: _import('errorPage/404'), hidden: true },
]

export const systems = [
    {
        path: '/system',  component: Layout, children: [
            {
                path: '',
                component: _import('system/index'),
                name: 'system',
                meta: { title: 'system.systems', dashboard: 'system.dashboard', panel: "systems", header_title: "系统列表" }
            },
            {
                path: ':id',
                component: _import('system/detail/index'),
                name: 'system_detail',
                hidden: true,
                children: [
                    {
                        path: '',
                        component: _import('system/detail/packageList'),
                        name: 'system.package_list',
                        hidden: true,
                        meta: {
                            title: 'system.systems',
                            dashboard: 'system.dashboard',
                            noCache: true,
                            panel: "systems",
                            header_title: "系统列表-软件包列表",
                            breadcrumb: [
                                { name: 'system.systems', path: '/system/' },
                                { name: 'system.package_list' }
                            ]
                        }
                    },
                    {
                        path: 'package_change_log',
                        component: _import('system/detail/packageChangeLog'),
                        name: 'system.package_changelog',
                        hidden: true,
                        meta: {
                            title: 'system.systems',
                            dashboard: 'system.dashboard',
                            noCache: true,
                            panel: "systems",
                            header_title: "系统列表-软件包变更记录",
                            breadcrumb: [
                                { name: 'system.systems', path: '/system/' },
                                { name: 'system.package_changelog' }
                            ]
                        }
                    },
                    {
                        path: 'configure_changelog',
                        component: _import('system/detail/configureChangeLog'),
                        name: 'configure.changelog',
                        hidden: true,
                        meta: {
                            title: 'system.systems',
                            dashboard: 'system.dashboard',
                            panel: "systems",
                            header_title: "系统列表-配置变更记录",
                            noCache: true,
                            breadcrumb: [
                                { name: 'system.systems', path: '/system/' },
                                { name: 'configure.changelog' }
                            ]
                        }
                    },
                    {
                        path: 'configure_item',
                        component: _import('system/detail/configureItem'),
                        name: 'configure.list',
                        hidden: true,
                        meta: {
                            title: 'system.systems',
                            header_title: "系统列表-配置项列表",
                            noCache: true,
                            dashboard: 'system.dashboard',
                            panel: "systems",
                            breadcrumb: [
                                { name: 'system.systems', path: '/system/' },
                                { name: 'configure.list' }
                            ]
                        }
                    },
                ]
            }
        ]
    },
    {
        path: '/batch', component: Layout, children: [
            {
                path: '',
                component: _import('batch/index'),
                name: 'host_batch',
                meta: { title: 'system.host_batch', dashboard: 'system.dashboard', panel: "batch", header_title: "批次处理", }
            },
            {
                path: ':id',
                hidden: true,
                component: _import('batch/detail/index'),
                name: 'host_batch_detail',
                meta: {
                    dashboard: 'system.dashboard',
                    panel: "batch",
                    header_title: "批次处理",
                    noCache: true,
                    breadcrumb: [
                        { name: 'system.host_batch', path: '/batch/' },
                        { name: 'detail' }
                    ]
                }
            }
        ]
    },
    {
        path: '/scan_setting', component: Layout, children: [
            {
                path: '',
                component: _import('scanSetting/index'),
                name: 'scan_setting',
                meta: { title: 'system.scan_setting', header_title: "扫描设置", dashboard: 'system.dashboard', panel: "scan_setting" }
            }
        ]
    },
    {
        path: '/compare', component: Layout, children: [
            {
                path: '',
                component: _import('compare/index'),
                name: 'system_compare',
                meta: { title: 'system.system_compare', header_title: "系统对比", dashboard: 'system.dashboard', panel: "system_compare" }
            }
        ]
    },
    /* {
        path: '/register', component: Layout, children: [
            {
                path: '',
                component: _import('register/index'),
                name: 'register',
                meta: { title: 'system.register', role: ['admin'], dashboard: 'system.dashboard', panel: "register" }
            }
        ]
    }, */
    {
        path: '/script', component: Layout, children: [
            {
                path: '',
                component: _import('script/index'),
                name: 'script',
                meta: { title: 'system.script', header_title: "自定义脚本", dashboard: 'system.dashboard', panel: "script" }
            }
        ]
    }
]

export const configures = [
    {
        path: '/configure',
        name: 'configure.configure_manager',
        component: Layout,
        children: [
            {
                path: '/configure/normal_library',
                component: _import('normalLibrary/home'),
                children: [
                    {
                        path: '',
                        component: _import('normalLibrary/index'),
                        name: 'normal_library_index',
                        meta: {
                            title: 'configure.normal_library',
                            dashboard: 'configure.dashboard',
                            panel: "normal_library",
                            header_title: "标准库管理",
                        },
                    },
                    {
                        path: ':id',
                        hidden: true,
                        component: _import('normalLibrary/detail/index'),
                        name: 'normal_library_detail',
                        meta: {
                            title: 'configure.normal_library',
                            dashboard: 'configure.dashboard',
                            noCache: true,
                            panel: "normal_library",
                            header_title: "标准库管理-配置项列表",
                            breadcrumb: [
                                { name: 'configure.normal_library', path: '/configure/normal_library/' },
                                { name: 'configure.configure_item' }
                            ]
                        },
                    }
                ]
            },
            {
                path: 'configure_item',
                component: _import('configureItem/index'),
                name: 'configure_item',
                meta: {
                    title: 'configure.configure_item_manager',
                    dashboard: 'configure.dashboard',
                    header_title: "配置项列表",
                    panel: "configure_item"
                }
            },
            {
                path: '/configure/configure_group',
                component: _import('configureGroup/home'),
                children: [
                    {
                        path: '',
                        component: _import('configureGroup/index'),
                        name: 'configure_group_index',
                        meta: {
                            title: 'configure.configure_group',
                            dashboard: 'configure.dashboard',
                            panel: "configure_group",
                            header_title: "配置项组管理",
                        },
                    },
                    {
                        path: ':id',
                        hidden: true,
                        component: _import('configureGroup/detail/index'),
                        name: 'configure_group_detail',
                        meta: {
                            title: 'configure.configure_group',
                            dashboard: 'configure.dashboard',
                            noCache: true,
                            panel: "configure_group",
                            header_title: "配置项组管理-配置项列表",
                            breadcrumb: [
                                { name: 'configure.configure_group', path: '/configure/configure_group/' },
                                { name: 'configure.configure_item' }
                            ]
                        },
                    }
                ]
            },
        ]
    },
    {
        path: '/suse_migrate_tool',
        component: Layout,
        name: "configure.suse_migrate_tool",
        children: [
            {
                path: "/suse_migrate_tool/migrate_compare",
                component: _import('migrateCompare/home'),
                children: [
                    {
                        path: "",
                        component: _import("migrateCompare/index"),
                        name: 'migrate_compare_index',
                        meta: {
                            title: 'configure.migrate_compare',
                            dashboard: "configure.dashboard",
                            panel: "migrate_compare",
                            header_title: "迁移对比",
                        }
                    },
                    {
                        path: ":id",
                        hidden: true,
                        component: _import("migrateCompare/detail/index"),
                        name: 'migrate_compare_detail',
                        meta: {
                            title: 'configure.migrate_compare',
                            dashboard: 'configure.dashboard',
                            panel: "migrate_compare",
                            noCache: true,
                            header_title: "迁移对比-测试校验",
                            breadcrumb: [
                                { name: 'configure.migrate_compare', path: '/suse_migrate_tool/migrate_compare/' },
                                { name: 'configure.test_verification' }
                            ]
                        },
                    }
                ]
            },
            {
                path: 'template_library',
                component: _import('templateLibrary/index'),
                name: 'template_library',
                meta: {
                    title: 'configure.template_library',
                    header_title: "模板库",
                    dashboard: 'configure.dashboard',
                    panel: "template_library"
                }
            }
        ]
    }
]

export const patchs = [
    {
        path: '/patch',
        component: Layout,
        children: [
            {
                path: 'product',
                component: _import('product/index'),
                name: 'product',
                meta: {
                    title: 'patch.product',
                    dashboard: 'patch.dashboard',
                    panel: "product",
                    header_title: "产品源",
                }

            },
            {
                path: 'product/:id',
                component: _import('product/detail/index'),
                name: 'product_detail',
                hidden: true,
                children: [
                    {
                        path: '',
                        component: _import('product/detail/detail'),
                        name: 'detail',
                        hidden: true,
                        meta: {
                            title: 'patch.product',
                            header_title: "产品源-详情",
                            dashboard: 'patch.dashboard',
                            noCache: true,
                            panel: "product",
                            breadcrumb: [
                                { name: 'patch.product', path: '/patch/product' },
                                {
                                    name: function (data) {
                                        return `${data.selectProd}`
                                    }, path: function (route) {
                                        return `/patch/product/${route.params.id}`
                                    }
                                }
                            ]
                        }
                    },
                    {
                        path: 'repositories',
                        component: _import('product/detail/packageGroup'),
                        name: 'patch.package_group',
                        hidden: true,
                        meta: {
                            title: 'patch.product',
                            dashboard: 'patch.dashboard',
                            panel: "product",
                            noCache: true,
                            header_title: "产品源-软件包组",
                            breadcrumb: [
                                { name: 'patch.product', path: '/patch/product' },
                                {
                                    name: function (data) {
                                        return `${data.selectProd}`
                                    }, path: function (route) {
                                        return `/patch/product/${route.params.id}`
                                    }
                                },
                                {
                                    name: 'patch.package_group'
                                }
                            ]
                        }
                    },
                    {
                        path: 'repositories/:detailId',
                        component: _import('product/detail/packageDummy'),
                        name: 'patch.package_group_details',
                        hidden: true,
                        children: [
                            {
                                path: '',
                                component: _import('product/detail/packageGroupDetail'),
                                name: 'patch.package_group_detail',
                                hidden: true,
                                meta: {
                                    title: 'patch.product',
                                    dashboard: 'patch.dashboard',
                                    header_title: "产品源-软件包组-详情",
                                    noCache: true,
                                    panel: "product",
                                    breadcrumb: [
                                        { name: 'patch.product', path: '/patch/product' },
                                        {
                                            name: function (data) {
                                                return `${data.selectProd}`
                                            }, path: function (route) {
                                                return `/patch/product/${route.params.id}`
                                            }
                                        },
                                        {
                                            name: 'patch.package_group', path: function (route) {
                                                return `/patch/product/${route.params.id}/repositories`
                                            }
                                        },
                                        {
                                            name: function (data) {
                                                return `${data.selectRepo}`
                                            }, path: function (route) {
                                                return `/patch/product/${route.params.id}/repositories/${route.query.id2}`
                                            }
                                        },
                                    ]
                                },
                            },
                            {
                                path: 'content',
                                component: _import('product/detail/packageList'),
                                name: 'patch.package_group_rpms',
                                hidden: true,
                                meta: {
                                    title: 'patch.product',
                                    dashboard: 'patch.dashboard',
                                    panel: "product",
                                    header_title: "产品源-软件包组-内容",
                                    noCache: true,
                                    breadcrumb: [
                                        { name: 'patch.product', path: '/patch/product' },
                                        {
                                            name: function (data) {
                                                return `${data.selectProd}`
                                            }, path: function (route) {
                                                return `/patch/product/${route.params.id}`
                                            }
                                        },
                                        {
                                            name: 'patch.package_group', path: function (route) {
                                                return `/patch/product/${route.params.id}/repositories`
                                            }
                                        },
                                        {
                                            name: function (data) {
                                                return `${data.selectRepo}`
                                            }, path: function (route) {
                                                return `/patch/product/${route.params.id}/repositories/${route.query.repoId}?id2=${route.query.repoId}`
                                            }
                                        },
                                        { name: 'content' },
                                    ]
                                },
                            }
                        ]
                    },
                    {
                        path: 'hosts',
                        component: _import('product/detail/hosts'),
                        name: 'system.dashboard',
                        hidden: true,
                        meta: {
                            title: 'patch.product',
                            dashboard: 'patch.dashboard',
                            noCache: true,
                            panel: "product",
                            breadcrumb: [
                                { name: 'patch.product', path: '/patch/product' },
                                { name: 'system.dashboard' }
                            ]
                        }
                    },

                ]
            }
        ]
    },
    {
        path: '/packages',
        component: Layout,
        children: [
            {
                path: '', component: _import('packages/index'),
                name: 'packages',
                meta: {
                    title: 'patch.packages',
                    dashboard: 'patch.dashboard',
                    panel: "packages",
                    header_title: "软件包列表",
                }
            },
            {
                path: ':id',
                hidden: true,
                component: _import('packages/detail/index'),
                children: [
                    {
                        path: '',
                        name: 'patch.packages_detail',
                        component: _import('packages/detail/detail'),

                        meta: {
                            dashboard: 'patch.dashboard',
                            panel: "packages",
                            noCache: true,
                            header_title: "软件包列表-详情",
                            breadcrumb: [
                                { name: 'patch.packages', path: '/packages/' },
                                { name: 'patch.packages_detail' }
                            ]
                        }
                    },
                    {
                        path: 'files',
                        name: 'patch.file',
                        component: _import('packages/detail/file'),
                        meta: {
                            dashboard: 'patch.dashboard',
                            panel: "packages",
                            header_title: "软件包列表-文件",
                            noCache: true,
                            breadcrumb: [
                                { name: 'patch.packages', path: '/packages/' },
                                { name: 'patch.packages_detail' }
                            ]
                        }
                    },
                    {
                        path: 'dependencies',
                        name: 'patch.dependencies',
                        component: _import('packages/detail/dependencies'),
                        meta: {
                            dashboard: 'patch.dashboard',
                            header_title: "软件包列表-依赖包",
                            noCache: true,
                            panel: "packages",
                            breadcrumb: [
                                { name: 'patch.packages', path: '/packages/' },
                                { name: 'patch.packages_detail' }
                            ]
                        }
                    },
                    {
                        path: 'repositories',
                        name: 'patch.repositories',
                        component: _import('packages/detail/repositories'),
                        meta: {
                            dashboard: 'patch.dashboard',
                            header_title: "软件包列表-软件包组",
                            noCache: true,
                            panel: "packages",
                            breadcrumb: [
                                { name: 'patch.packages', path: '/packages/' },
                                { name: 'patch.packages_detail' }
                            ]
                        }
                    }
                ]

            }
        ]

    },
    {
        path: '/sp_upgrade',
        component: Layout,
        children: [
            {
                path: '', component: _import('spupgrade/index'),
                name: 'sp_upgrade',
                meta: {
                    title: 'patch.sp_upgrade',
                    dashboard: 'patch.dashboard',
                    panel: "sp_upgrade",
                    header_title: "SP升级",
                }
            },
            {
                path: ':id',
                hidden: true,
                component: _import('spupgrade/detail/index'),
                name: 'sp_upgrade_detail',
                meta: {
                    dashboard: 'patch.dashboard',
                    panel: "sp_upgrade",
                    header_title: "SP升级-详情",
                    noCache: true,
                    breadcrumb: [
                        { name: 'patch.sp_upgrade', path: '/sp_upgrade/' },
                        { name: 'patch.sp_upgrade_detail' }
                    ]
                }
            }
        ]

    },
    {
        path: '/cvelist',
        component: Layout,
        children: [
            {
                path: '', component: _import('cvelist/index'),
                name: 'cvelist',
                meta: {
                    title: 'patch.cve_list',
                    dashboard: 'patch.dashboard',
                    panel: "cvelist",
                    header_title: "cve列表",
                }
            }
        ]
    
    },
    {
        path: '/cve_group',
        component: Layout,
        children: [
            {
                path: "",
                component: _import("cveGroup/index"),
                name: "cve_group",
                meta: {
                    title: "patch.cve_group",
                    dashboard: "patch.dashboard",
                    header_title: "cve组",
                    panel: "cve_group"
                }
            },
            {
                path: ':id',
                hidden: true,
                component: _import('cveGroup/detail/index'),
                name: 'cve_group_detail',
                meta: {
                    dashboard: 'patch.dashboard',
                    panel: "cve_group",
                    header_title: "cve组-详情",
                    noCache: true,
                    breadcrumb: [
                        { name: 'patch.cve_group', path: '/cve_group/' },
                        { name: 'patch.cve_group_detail' }
                    ]
                }
            }
        ]
    },
]

export const users = [
    {
        path: '/user',
        component: Layout,
        children: [
            {
                path: "",
                component: _import("user/index"),
                name: "user",
                meta: {
                    title: "user.user_manager",
                    dashboard: "user.dashboard",
                    header_title: "用户管理",
                    panel: "user"
                }
            }
        ]
    },
    {
        path: '/roles',
        component: Layout,
        children: [
            {
                path: "",
                component: _import("roles/index"),
                name: "roles",
                meta: {
                    title: "user.role_manager",
                    dashboard: "user.dashboard",
                    panel: "roles",
                    header_title: "角色管理",
                }
            }
        ]
    },
    {
        path: '/user_operation',
        component: Layout,
        children: [
            {
                path: "",
                component: _import("userOperation/index"),
                name: "user_operation",
                meta: {
                    title: "user.user_operation",
                    dashboard: "user.dashboard",
                    panel: "user_operation",
                    header_title: "用户组操作",
                }
            }
        ]
    }
]

export const logs = [
    {
        path: '/log',
        component: Layout,
        children: [
            {
                path: '',
                component: _import('log/index'),
                name: 'log',
                meta: {
                    title: 'log.log',
                    dashboard: 'log.dashboard',
                    panel: "log",
                    header_title: "日志",
                }
            },
            {
                path: ':id',
                hidden: true,
                component: _import('log/detail/index'),
                name: 'log_detail',
                meta: {
                    dashboard: 'log.dashboard',
                    panel: "log",
                    noCache: true,
                    header_title: "日志-详情",
                    breadcrumb: [
                        { name: 'log.log', path: '/log/' },
                        { name: 'detail' }
                    ]
                }
            }
        ]
    },
]
export const notfound = [
    { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
    mode: 'history',
    routes: [
        ...constantRouterMap,
        ...systems,
        ...configures,
        ...patchs,
        ...users,
        ...logs,
        ...notfound
    ]
})
